home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / newlooklib.lha / newlook / createlistview.c < prev    next >
C/C++ Source or Header  |  1993-10-24  |  3KB  |  104 lines

  1. /*
  2.  *  CREATELISTVIEW.C
  3.  */
  4.  
  5. #include "newlook.h"
  6.  
  7. extern LONG IntuiTextLength(struct IntuiText *);
  8.  
  9. static struct IntuiText itext= {
  10.  1,0,JAM1,0,0,&Topaz80,NULL,(struct IntuiText *)NULL
  11. };
  12.  
  13. struct Gadget *CreateListView(x,y, c,l, tlist, id)
  14. SHORT x,y;
  15. SHORT c,l;
  16. STRPTR *tlist;
  17. USHORT id;
  18. {
  19.   struct Gadget *glist,      /* indexed (id,...,id+l-1) */
  20.                 *slider;     /* indexed (id+l,...,id+l+2) */
  21.  
  22.   struct IntuiText *itlist;
  23.   struct Border *b;
  24.  
  25.   SHORT n,w,h, tlines=0; /* #of text lines given */
  26.   STRPTR *t;
  27.  
  28.   ULONG UserHandle= SetNewLookHandle(PRIVATE_HANDLE);
  29.  
  30.   /* adjust parameters */
  31.   if(l<3) l=3;
  32.   if(c<1) c=1;
  33.  
  34.   w= c * 8;        /* Here we expect topaz.font to be */
  35.   h= l * (1+8+1);  /* a non-proportional 8x8 font     */
  36.  
  37.   if(tlist)
  38.   {
  39.     /* compute tlist dimensions: cmax, lmax, w, h */
  40.     for(t= tlist; *t; t++, tlines++)
  41.     {
  42.       if((n= strlen(*t)) > c)
  43.         c= n;
  44.  
  45.       itext.IText= *t;
  46.       if((n= IntuiTextLength(&itext)) > w)
  47.         w= n;
  48.     }
  49.   }
  50.  
  51.   if((w+=4)>4 && h>0)
  52.   {
  53.     if(b= CreateBorder(-2,-1, 2+w+2,h+2, FALSE))
  54.     {
  55.       if(slider= CreateSlider(x+w+4,y-1,h+2,"B",id+l))
  56.       {
  57.         if(glist= (struct Gadget *)SmartAllocate(l*GADGETSIZE))
  58.         {
  59.           if(itlist= (struct IntuiText *)SmartAllocate(l*ITEXTSIZE))
  60.           {
  61.             for(n=0, t=tlist; n<l; n++)
  62.             {
  63. /**/          itlist[n].FrontPen     = 1;
  64.               itlist[n].BackPen      = 0;
  65.               itlist[n].DrawMode     = JAM1;
  66.               itlist[n].LeftEdge     = 2;
  67.               itlist[n].TopEdge      = 1;
  68.               itlist[n].ITextFont    = &Topaz80;
  69.               itlist[n].IText        = (n<tlines) ? *t++ : NULL;
  70.               itlist[n].NextText     = (struct IntuiText *)NULL;
  71.  
  72. /**/          glist[n].NextGadget    = (n<(l-1)) ? &glist[n+1] : slider;
  73.               glist[n].LeftEdge      = x+2;
  74.               glist[n].TopEdge       = y + n * (1+8+1);
  75.               glist[n].Width         = w;
  76.               glist[n].Height        = (1+8+1);
  77.               glist[n].Flags         = GADGHCOMP;
  78.               glist[n].Activation    = GADGIMMEDIATE|RELVERIFY;
  79.               glist[n].GadgetType    = BOOLGADGET;
  80.               glist[n].GadgetRender  = (APTR)NULL;
  81.               glist[n].SelectRender  = (APTR)NULL;
  82.               glist[n].GadgetText    = (struct IntuiText *)&itlist[n];
  83.               glist[n].MutualExclude = (LONG)0L;
  84.               glist[n].SpecialInfo   = (APTR)NULL;
  85.               glist[n].GadgetID      = id+n;
  86.               glist[n].UserData      = (APTR)NULL;
  87.             }
  88.  
  89.             glist[0].GadgetRender= b;
  90.  
  91.             MakePrivateHandlePublic(UserHandle);
  92.             return glist;
  93.           }
  94.         }
  95.       }
  96.     }
  97.   }
  98.   if(UserHandle != PRIVATE_HANDLE)
  99.   { SmartFreeAll(PRIVATE_HANDLE);
  100.     (void)SetNewLookHandle(UserHandle);
  101.   }
  102.   return (struct Gadget *)NULL;
  103. }
  104.